using System;
using System.Collections;
using Rdl;

namespace GTame.ReportParser
{

    public class QueryType
    {

        private string _CommandText;
        private QueryTypeCommandType _CommandType;
        private string _DataSourceName;
        private QueryParametersType _QueryParameters;
        private Nullable<uint> _Timeout;

        public string CommandText
        {
            get
            {
                return _CommandText;
            }
            set
            {
                _CommandText = value;
            }
        }

        public QueryTypeCommandType CommandType
        {
            get
            {
                return _CommandType;
            }
            set
            {
                _CommandType = value;
            }
        }

        public string DataSourceName
        {
            get
            {
                return _DataSourceName;
            }
            set
            {
                _DataSourceName = value;
            }
        }

        public QueryParametersType QueryParameters
        {
            get
            {
                if (_QueryParameters == null)
                    _QueryParameters = new QueryParametersType();
                return _QueryParameters;
            }
            set
            {
                _QueryParameters = value;
            }
        }

        public Nullable<uint> Timeout
        {
            get
            {
                return _Timeout;
            }
            set
            {
                _Timeout = value;
            }
        }

        public QueryType()
        {
            _Timeout = new Nullable<uint>[]();
        }

        public QueryType Write()
        {
            QueryType queryType = new QueryType();
            ArrayList arrayList1 = new ArrayList();
            ArrayList arrayList2 = new ArrayList();
            if (_CommandText != null)
            {
                arrayList1.Add(_CommandText);
                arrayList2.Add(1);
            }
            arrayList1.Add(_CommandType);
            arrayList2.Add(2);
            if (_DataSourceName != null)
            {
                arrayList1.Add(_DataSourceName);
                arrayList2.Add(3);
            }
            if (_QueryParameters != null)
            {
                arrayList1.Add(_QueryParameters.Write());
                arrayList2.Add(4);
            }
            if (_Timeout.get_HasValue())
            {
                arrayList1.Add(_Timeout);
                arrayList2.Add(5);
            }
            queryType.Items = arrayList1.ToArray();
            queryType.ItemsElementName = (ItemsChoiceType2[])arrayList2.ToArray(typeof(ItemsChoiceType2));
            arrayList2 = arrayList1 = null;
            return queryType;
        }

    } // class QueryType

}

